//
// Created by tianq on 24-12-9.
//
// This is a stupid brute-forced implementation, but it must work
// it takes 135786 calculations for 7 inputs LOL, the time & space complexity is VERY BAD
// time: $O(n!^2)$, space: $O(n!)$
// hint: n=9: 136873332calc(5min), 57153600vectors(2340mb), problem size must be 8 or less
//
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

int main() {
    int n = 0;
    vector<int> numbers;

    cin >> n;
    for (int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        numbers.push_back(tmp);
    }

    // brute force version: try every possible combinations, until only one left
    // we are not bundling a problem generator here
    unsigned long long calc = 0;
    unsigned long long memMax = 0;
    vector<int> results;
    queue<pair<int,vector<int>>> q;
    q.emplace(0,numbers);

    while (!q.empty()) {
        memMax = max(memMax, q.size());

        auto [score, piles] = q.front();
        q.pop();

        if (piles.size() < 2) {
            results.emplace_back(score);
            // cout << score << endl;
            continue;
        }

        // choose 2 numbers from v and push new task to q
        for (int i = 0; i < piles.size() - 1; i++) {
            for (int j = i + 1; j < piles.size(); j++) {
                const int a = piles[i];
                const int b = piles[j];
                const int sum = a + b;  // p4 brute: modified this line
                calc ++;
                vector<int> newPiles = piles;
                newPiles.erase(newPiles.begin() + j);
                newPiles.erase(newPiles.begin() + i);
                newPiles.emplace_back(sum);
                q.emplace(score+sum, newPiles);
            }
        }
    }

    const int max = ranges::max(results);
    const int min = ranges::min(results);
    cout << "calc: " << calc << ", memMax: " << memMax << " vectors" << endl;
    cout << "max: " << max << ", min: " << min << endl;
    cout << "M: " << max - min << endl;
    return 0;
}
